// GTK+的组合构件通常是由多个基础构件结合而成，拥有更加强大的功能，
// 常见的组合构件有对话框、组合框和日历构件等
/* 该案例是一个使用对话框控件实现退出提示的实例
 * struct GtkDialog{
 *	GtkWindow window;
 *	GtkWidget *vbox;
 *	GtkWidget *action_area;
 * }
 *
 * */

#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>

// 按键回调函数处理函数
void destory(GtkWidget *widget, gpointer *data){
	// gtk_widget_destroy函数为删除一个构件
	gtk_widget_destroy(GTK_WIDGET(data));
}

// 按键的回调函数
gint button_deal(GtkWidget *widget, gpointer *data){
	// 创建按钮和对话框
	GtkWidget *button,*dialog;

	dialog = gtk_dialog_new();
	button = gtk_button_new_with_label("YES");

	// 将button添加到对话框的操作区
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area),button,TRUE,TRUE,0);
	gtk_signal_connect(GTK_OBJECT(button),"clicked",G_CALLBACK(gtk_main_quit),NULL);
	gtk_widget_show(button);

	button = gtk_button_new_with_label("NO");
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area),button,TRUE,TRUE,0);
	gtk_signal_connect(GTK_OBJECT(button),"clicked",G_CALLBACK(destory),NULL);
	gtk_widget_show(button);

	gtk_widget_show(dialog);

}

int main(int argc, char *argv[]){
	
	GtkWidget *window,*button;
	char title[] = "对话框测试";

	gtk_init(&argc,&argv);
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(window),"GtkDialog_test");
	gtk_widget_set_usize(window,300,250);
	gtk_widget_set_uposition(window,300,300);
	gtk_signal_connect(GTK_OBJECT(window),"destory",G_CALLBACK(gtk_main_quit),NULL);

	// 创建按钮,并将其添加到窗体中
	button = gtk_button_new_with_label("Exit");
	gtk_container_add(GTK_WINDOW(window),button);
	// 对按钮创建点击的回调函数
	gtk_signal_connect(GTK_OBJECT(button),"clicked",G_CALLBACK(button_deal),"clicked");
	
	gtk_widget_show(button);
	gtk_widget_show(window);
	gtk_main();

	return 0;
}

